package com.zodiac.app.szse.sse.stockdata.dto;

import com.zodiac.app.szse.sse.SseCommonResponse;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.EnumUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 股票数据-每日概况
 */
@Data
public class SseStockDataOverviewDayResponse extends SseCommonResponse {

    private String prodType;
    private String searchDate;
    private List<Result> result;

    @NoArgsConstructor
    @Data
    public static class Result {
        private String depositVol;
        private String exchangeRate;
        private String istVol;
        private String marketValue;
        private String marketValue1;
        private String negotiableValue;
        private String negotiableValue1;
        private String productType;
        private String profitRate;
        private String profitRate1;
        private String searchDate;
        private String trdAmt;
        private String trdAmt1;
        private String trdTm;
        private String trdTm1;
        private String trdVol;
        private String trdVol1;
    }

    public enum ProductType {
        ALL("12", "股票"),
        A("1", "A股"),
        B("2", "B股"),
        K("48", "科创板");

        private final String type;
        private final String description;

        ProductType(String type, String description) {
            this.type = type;
            this.description = description;
        }

        public String getType() {
            return type;
        }

        public String getDescription() {
            return description;
        }

        public static ProductType of(String type) {
            return EnumUtils.getEnumList(ProductType.class).stream().filter(v -> v.getType().equals(type)).findFirst().orElse(null);
        }
    }

    /**
     * 转换格式
     *
     * @return
     */
    public Map<ProductType, Result> transform() {
        final List<String> types = Arrays.stream(ProductType.values()).map(ProductType::getType).collect(Collectors.toList());
        return getResult().stream().filter(v -> types.contains(v.getProductType())).collect(Collectors.toMap(v -> ProductType.of(v.getProductType()), Function.identity()));
    }

}
